﻿using System;
using System.Configuration;
using System.IO;
using System.Web.Mvc;

namespace PermissionsManager.Attribute
{
    public class ExceptionHandleErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
            //父类捕获异常
            base.OnException(filterContext);

            string exception = filterContext.Exception.ToString();

            string controllername = filterContext.RouteData.Values["Controller"].ToString();

            string actionname = filterContext.RouteData.Values["Action"].ToString();

            string msg = $"时间:{DateTime.Now},在控制器:{controllername},方法:{actionname}出现了异常:{exception}";

            string path = ConfigurationManager.AppSettings["exceptionPath"];

            File.AppendAllText(path,msg);
        }
    }
}